package com.example.goodog.items;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Parcel;
import android.os.Parcelable;

import com.example.goodog.interfaces.IItemWithLocation;

public abstract class ListItem implements Parcelable, IItemWithLocation{
	public long ID;
	public byte[] ImageBlob;
	Bitmap m_bmp;
	private int PageNumber;
	public double	PLat;
	public double	PLong;
		
	public ListItem()
	{
	}
	
	public Bitmap getBitmap(){
		if(m_bmp == null && ImageBlob != null)
		{
			m_bmp = BitmapFactory.decodeByteArray(ImageBlob,0,ImageBlob.length);
		}
		return m_bmp;
	}
	


	
	public int GetPageNumber()
	{
		return PageNumber;
	}
	
	public double GetLat()
	{
		return PLat;
	}
	
	public double GetLong()
	{
		return PLong;
	}
	
	public void SetPageNumber(int pageNumber)
	{
		PageNumber = pageNumber;
	}
	
	
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel parcel, int flags) {
		parcel.writeLong(ID);  
		 //parcel.writeByteArray(ImageBlob);  
		 parcel.writeParcelable(m_bmp,flags); 
		 parcel.writeInt(PageNumber);
		 parcel.writeDouble(PLat);
		 parcel.writeDouble(PLong);
	}
	
	
	protected void readFromParcel(Parcel parcel) {   
		ID = parcel.readLong();
		//ImageBlob = parcel.readByteArray();
		m_bmp = (Bitmap)parcel.readParcelable(getClass().getClassLoader());
		PageNumber = parcel.readInt();


		PLat = parcel.readDouble(); 
		PLong = parcel.readDouble(); 
		
	}
	
	public boolean equals(Object obj) {
	       
		if (obj==null || !(obj instanceof ListItem))
	            return false;
		return((ListItem)obj).ID == this.ID;    
	    }	
}
